#!/usr/bin/env sh

echo "15672：控制台端口号"
echo "5672：应用访问端口号"

set -e
name=rabbit
[ $1 ] && name=$1

# echo "name=$name"
running=`docker ps | grep $name | awk '{print $2}'`
stoped=`docker ps -a | grep $name | awk '{print $2}'`

# echo $running
# echo $stoped
if [ $running ]
then
	echo "$name 正在运行!"
	exit
fi

if [ $stoped ]
then
	echo "$name 重新启动！"
	docker start $name > /dev/null 2>&1
	exit
fi


# docker stop rabbit 
# docker rm rabbit
docker run -d --hostname my-rabbit \
 --name $name \
 -e RABBITMQ_DEFAULT_USER=admin \
 -e RABBITMQ_DEFAULT_PASS=admin \
 -p 15672:15672 \
 -p 5672:5672 \
 -p 25672:25672 \
 -p 61613:61613 \
 -p 1883:1883 \
 rabbitmq:management > /dev/null 2>&1

if [ $? != 0 ]
then
	echo '$name未能正常启动！'
else
	[ `docker ps | grep $name | awk '{print $2}'` ] && echo "success!"
fi